#include <QtGui>
#include <QtCore/QTextCodec>
#include <QTranslator>
#include "gv_setuphomedialog.h"
#include "gv_setupchangepwddiaglog.h"
#include "gv_setuplanguagedialog.h"
#include "gv_setuptimedialog.h"
#include "gv_setupdatedialog.h"
#include "gv_setuptimezonedialog.h"
#include "gv_home.h"
#include "gv_setting.h"

extern GV_Setting *gvsetting;
extern QDialog  *dialog;
GV_SetupHomeDialog::GV_SetupHomeDialog(QWidget *parent)
       : QDialog(parent)
{
    setupUi(this);

    QTranslator translator;
    translator.load(gvsetting->GV_GetLanguage(),".");
    qApp->installTranslator(&translator);
    reloadtext();

    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));

    timer = new QTimer;
    connect(timer,SIGNAL(timeout()),this,SLOT(GV_chTime()));
    connect(BackButton,SIGNAL(clicked()),this,SLOT(home()));
    connect(CancelButton,SIGNAL(clicked()),this,SLOT(home()));

    connect(ChangePWDButton,SIGNAL(clicked()),this,SLOT(changepwd()));
    connect(TimeanddateButton,SIGNAL(clicked()),this,SLOT(timeanddate()));
    connect(LanguageselectionButton,SIGNAL(clicked()),this,SLOT(changelanguage()));
    timer->start(1000);
}

void GV_SetupHomeDialog::reloadtext()
{
    NameHintsLabel->setText(tr("User's Setup"));

    ChangePWDButton->setText(tr("Change Password"));
    TimeanddateButton->setText(tr("Time and Date"));
    LanguageselectionButton->setText(tr("Language Selection"));

    HelpButton->setText(tr("Help"));
    CancelButton->setText(tr("Cancel"));
    BackButton->setText(tr("Back"));
}

void GV_SetupHomeDialog::GV_chTime()
{
    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
}

void GV_SetupHomeDialog::home()
{
    QDialog *dialog1 = new gv_home;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void GV_SetupHomeDialog::changepwd()
{
    QDialog *dialog1 = new GV_SetupChangePWDDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void GV_SetupHomeDialog::timeanddate()
{
    QDialog *dialog1 = new GV_SetupTimezoneDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void GV_SetupHomeDialog::changelanguage()
{
    QDialog *dialog1 = new GV_SetupLanguageDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}
